home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / InvisibleHTMLLink.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  4.7 KB  |  174 lines

  1. package symantec.itools.awt;
  2.  
  3.  
  4. import java.net.URL;
  5. import java.awt.Event;
  6. import java.awt.Container;
  7. import java.applet.*;
  8.  
  9.  
  10. /**
  11.  * Use this component to create an invisible rectangular button, usually within
  12.  * an image, that links to a URL address when clicked. Specifically, use 
  13.  * InvisibleHTMLLink to:
  14.  * <UL>
  15.  * <DT>╖ Accept or yield focus.</DT>
  16.  * <DT>╖ Respond to a user event.</DT>
  17.  * <DT>╖ Send an action event to another component.</DT>
  18.  * </UL>
  19.  * Button tips:
  20.  * <UL>
  21.  * <DT>╖ Buttons accept and yield focus automatically by default.</DT>
  22.  * <DT>╖ Buttons accept clicked events automatically by default.</DT>
  23.  * <DT>╖ To send an action event to another component, use the Interaction 
  24.  * Wizard. Optionally, you can override the InvisibleButtonÆs click event in 
  25.  * project source code.</DT>
  26.  * </UL>
  27.  * Implements the Runnable interface to support threads. An InvisibleHTMLLink 
  28.  * can be set from the Property List window to post continuous action events 
  29.  * when the button is clicked.
  30.  * <p>
  31.  * @version 1.0, Nov 26, 1996
  32.  * @author Symantec
  33.  */
  34. public class InvisibleHTMLLink
  35.     extends InvisibleButton
  36. {
  37.     /**
  38.      * URL to show when the button is clicked.
  39.      */
  40.     protected URL url;
  41.     /**
  42.      * Applet context that shows the URL.
  43.      */
  44.     protected AppletContext context;
  45.     /**
  46.      * Frame specifier for showing a URL document in a browser or applet 
  47.      * viewer. It is interpreted as follows:
  48.      * <UL>
  49.      * <DT>"_self"  show document in the current frame</DT>
  50.      * <DT>"_parent"    show document in the parent frame</DT>
  51.      * <DT>"_top"   show document in the topmost frame</DT>
  52.      * <DT>"_blank" show document in a new unnamed toplevel window</DT>
  53.      * <DT>all others   show document in a new toplevel window with the given name</DT>
  54.      * </UL>
  55.      */
  56.     protected String frame;
  57.  
  58.     /**
  59.      * Constructs a default InvisibleHTMLLink.
  60.      */
  61.     public InvisibleHTMLLink()
  62.     {
  63.         frame = null;
  64.     }
  65.  
  66.     /**
  67.      * Returns the URL to show when the button is clicked.
  68.      * @see #setURL
  69.      */
  70.     public URL getURL()
  71.     {
  72.         return url;
  73.     }
  74.  
  75.     /**
  76.      * Sets the URL to show when the button is clicked.
  77.      * @param u the URL to show when the button is clicked
  78.      * @see #getURL
  79.      */
  80.     public void setURL(URL u)
  81.     {
  82.         url = u;
  83.         context = null;
  84.     }
  85.  
  86.     /**
  87.      * Sets the title displayed on the applet frame while showing
  88.      * the URL.
  89.      * @param f applet frame title
  90.      * @see #getFrame
  91.      */
  92.     public void setFrame(String f)
  93.     {
  94.         frame = f;
  95.     }
  96.  
  97.     /**
  98.      * Returns the title that is displayed on the applet frame while showing
  99.      * the URL.
  100.      * @see #setFrame
  101.      */
  102.     public String getFrame()
  103.     {
  104.         return frame;
  105.     }
  106.  
  107.     /**
  108.      * Handles internal actions for this component.
  109.      * This is a standard Java AWT method which usually gets called by the AWT
  110.      * method handleEvent() in response to receiving an ACTION_EVENT event. In those 
  111.      * cases the o parameter contains the value in the event's arg field.
  112.      * 
  113.      * @param e the event that caused this action
  114.      * @param o the action
  115.      * @return true if the action was handled
  116.      * @see java.awt.Component#handleEvent
  117.      */
  118.     public boolean action(Event event, Object what)
  119.     {
  120.         if (context != null)
  121.         {
  122.             if (frame == null || frame.length() == 0)
  123.                 context.showDocument(url);
  124.             else
  125.                 context.showDocument(url, frame);
  126.  
  127.             return true;
  128.         }
  129.  
  130.         return false;
  131.     }
  132.  
  133.     /**
  134.      * Ensures that this component is laid out properly, as needed.
  135.      * This is a standard Java AWT method which gets called by the AWT to 
  136.      * make sure this component and its subcomponents have a valid layout.
  137.      * If this component was made invalid with a call to invalidate(), then 
  138.      * it is laid out again.
  139.      * 
  140.      * It is overridden here to locate the applet containing this component.
  141.      *
  142.      * @see java.awt.Component#invalidate
  143.      */
  144.     public void validate()
  145.     {
  146.         // On validation, try to find the containing applet.  If we can find
  147.         // it, we don't bother doing the link...
  148.         Container c;
  149.  
  150.         c = getParent();
  151.  
  152.         while (c != null)
  153.         {
  154.             if (c instanceof Applet)
  155.             {
  156.                 setAppletContext(((Applet) c).getAppletContext());
  157.                 break;
  158.             }
  159.  
  160.             c = c.getParent();
  161.         }
  162.     }
  163.  
  164.     /**
  165.      * Sets the applet context to use for showing the URL.
  166.      * @param c the applet context
  167.      */
  168.     protected void setAppletContext(AppletContext c)
  169.     {
  170.         context = c;
  171.     }
  172. }
  173.  
  174.